/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.passport.service.plugins  
 */
package com.apache.passport.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.database.constant.SystemTools;
import com.apache.passport.common.DesUtils;
import com.apache.passport.entity.Token;

/**
 * description:  校验外部系统访问的token是否已失效
 * @author Hou Dayu 创建时间：2014-12-29  
 * @Copyright(c)2014:
 */
public class CheckTokenIdPlugin implements PluginConnector {

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo paramsvo) throws Exception {
		ResultEntity result = new ResultEntity();
		result.setResult("true");
		String tokenId = (String) paramsvo.getParams("tokenId");
		Token token = (Token) SystemTools.getInstance().getCache("loginToken").getCacheCloneByKey(tokenId);
		if (Validator.isEmpty(token)) {
			result.setEntity("F");
			result.setMessage("认证已过期或未登录");
			return result;
		}
		String loginType = String.valueOf(paramsvo.getParams("loginType"));
		if (Validator.isNull(loginType)) {
			result.setEntity(tokenId);
		} else {
			result.setEntity(token);
		}
		result.setMessage(DesUtils.getInstance().decrypt(token.getUserEname()));
		return result;
	}

}
